package com.lanyuan.a.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lanyuan.a.atest.BaseFormMap;
import com.lanyuan.a.bean.Article;
import com.lanyuan.a.bean.Food;
import com.lanyuan.a.dao.BaseDao;
import com.lanyuan.a.service.ArticleService;
import com.lanyuan.plugin.PageView;
@Service("articleService")
public class ArticleServiceImpl implements ArticleService {
	@Autowired
	public BaseDao<Article> baseDao;
	
	@Override
	public List<Article> list() {
		return baseDao.find("from Article");
	}

	@Override
	public List<Article> queryByPage(BaseFormMap formMap) {
		PageView pageView = (PageView)formMap.get("paging");
		int first = pageView.getPageNow();
		int max = pageView.getPageSize();
		String countHql = "select count (1) from Article a";
		Long count = baseDao.count(countHql);
		pageView.setRowCount(count);
		return baseDao.find("from Article a", new Object[]{}, first , max);
	
	}

	@Override
	public Article get(int id) {
		return baseDao.get("from Article a where id = ? ", new Object[]{id});
	}

	@Override
	public void saveOrUpdate(Article at) {
		baseDao.saveOrUpdate(at);
	}

	@Override
	public void deleteByIds(String[] ids) {
		Integer[] id = new Integer[ids.length];
		for(int i=0 ; i<ids.length; i++){
			System.out.println(ids[i]);
			id[i] = Integer.parseInt(ids[i]);
		}
		baseDao.delete("delete from Article u where u.id in (:ids)","ids" , id);
	}

}
